package icdecs.action;

import icdecs.action.form.SendLogActionForm;
import icdecs.mail.SimpleEmail;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class SendLogAction extends Action {

	private final static String SUCCESS = "success";
	private final static String FAILURE = "failure";

	private String txtDate;

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		SendLogActionForm sendLogForm = (SendLogActionForm) form;

		txtDate = (String) sendLogForm.getDate();
		SimpleEmail sendMail = new SimpleEmail();
		sendLogForm.setStatusMessage("Send mail success!");
		try {
			sendMail.sendMail(txtDate);
		} catch (Exception e) {
			e.printStackTrace();
			sendLogForm.setStatusMessage("Not file found at " + txtDate);
			return mapping.findForward(FAILURE);
		}

		return mapping.findForward(SUCCESS);
	}

}
